﻿
use p301
go

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER VIEW [dbo].[vKpo]
AS
SELECT     K_KPO, K_UKS, NPP_KPO, K_OBRASCH, F_DEN, F_KRIZIS, D_OBRASCH, V_OBRASCH, K_INF_CENTR, F_KLIENT, F_KONS, K_SPEC, K_HELP_ORG, 
                      N_HELP, K_SP, F_DETI, K_UP, K_OBR, K_SOCSTAT, K_RAB, K_PRICH, K_KONS, N_FA, N_IM, N_OT, K_POL, K_POM, N_PRIM, GOD_R, K_ADR, 
                      N_PRICH, ISNULL(D_KONS, CASE WHEN F_KONS = 1 THEN D_OBRASCH END) AS D_KONS, ISNULL(V_KONS, 
                      CASE WHEN F_KONS = 1 THEN V_OBRASCH END) AS V_KONS, LTRIM(STR(NPP_KPO)) + ' - ' + LTRIM(STR(YEAR(D_OBRASCH))) AS NPP_KPOyear, 
                      dbo.N_FIO(N_FA, N_IM, N_OT) AS N_FIO
FROM         dbo.b_kpo;
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

